<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/xhr.js"></script>
    <script>
        window.onload = function()
        {
            get_data();
            function get_data()
            {
                var data = document.getElementsByName("data1");
                var obj = data[0];
                var req = "read_registers1";
                XHR.postwait('/cgi-bin/web.cgi',req,function(x,info)
                {
                   // var da = info.split("0");
                    console.log(info);
                    obj.value = info;
                });
            }
            get_data1();
            function get_data1()
            {
                var data1 = document.getElementsByName("data2");
                var obj1 = data1[0];
                var req1 = "read_registers2";
                XHR.postwait('/cgi-bin/web.cgi',req1,function(x,info)
                {
                    console.log(info);
                    obj1.value = info;
                });
            }
        }
    </script>
    <script>
    function fun()
    {
        XHR.post('/cgi-bin/web.cgi',11,function(x,info){});
    }
    </script>

    <script>
    function fun1()
    {
        XHR.post('/cgi-bin/web.cgi',10,function(x,info){});
    }
    </script>
    <script>
    function fun2()
    {
        XHR.post('/cgi-bin/web.cgi',21,function(x,info){});
    }
    </script>
    <script>
    function fun3()
    {
        XHR.post('/cgi-bin/web.cgi',20,function(x,info){});
    }
    </script>
</head>
<body>
<h5>信息采集</h5>
<p>
光照传感器
<input type="text" name="data1" value=" ">
</p>
<p>
温度传感器
<input type="text" name="data2" value=" ">
</p>

<h5>设备控制</h5>
<p>
LED
<input type="radio" name="led" value="on" onclick="fun()">
<label for="on">on</label>
<input type="radio" name="led" value="off" onclick="fun1()">
<label for="off">off</label>
<br>
<p>
BEEP
<input type="radio" name="beep" value="on" onclick="fun2()">
<label for="on">on</label>
<input type="radio" name="beep" value="off" onclick="fun3()">
<label for="off">off</label>
</p>
</body>
</html>